gpsd: add hotplug handling
authorFlorian Eckert <[email protected]>
Thu, 30 Jan 2025 10:55:19 +0000 (11:55 +0100)
committerFlorian Eckert <[email protected]>
Fri, 28 Feb 2025 07:13:00 +0000 (08:13 +0100)
The 'gpsd' offers the possibility to call the script '/etc/gpsd/device-hook'
when a GPS source was added or removed via gpsdctl.

In addition to the '/etc/gpsd/device-hook' call an event is now triggered
too after the 'gpsd' has started. This allows scripts to configurre 'gpsd'
receivers.

The following events are available for '/etc/hotplug.d/gpsd' scripts:

* ACTIVATE   via '/etc/gpsd/device-hook'
* DEACTIVATE via '/etc/gpsd/device-hook'
* STARTED    via '/etc/init.d/gpsd'

Signed-off-by: Florian Eckert <[email protected]>
utils/gpsd/Makefile
utils/gpsd/files/etc/gpsd/device-hook [new file with mode: 0644]
utils/gpsd/files/etc/hotplug.d/gpsd/00-debug [new file with mode: 0644]
utils/gpsd/files/gpsd.init

index 5b52dcfb386738750bf7204eb1528a7aa5308e1a..ac568fbc2bc20bf5236b1ef4b1eb295e2a91c633 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=gpsd
 PKG_VERSION:=3.25
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
 PKG_SOURCE_URL:=@SAVANNAH/$(PKG_NAME)
@@ -141,6 +141,9 @@ define Package/gpsd/install
        $(INSTALL_BIN) ./files/gpsd.init $(1)/etc/init.d/gpsd
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/gpsd $(1)/usr/sbin/
+
+       $(INSTALL_DIR) $(1)/etc/gpsd
+       $(INSTALL_BIN) ./files/etc/gpsd/device-hook $(1)/etc/gpsd/
 endef
 
 define Package/gpsd-clients/install
diff --git a/utils/gpsd/files/etc/gpsd/device-hook b/utils/gpsd/files/etc/gpsd/device-hook
new file mode 100644 (file)
index 0000000..42f986c
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+main() {
+       local device="$1"
+       local action="$2"
+
+       case "$action" in
+               "ACTIVATE")
+                       env -i ACTION="$action" DEVICE="$device" \
+                               /sbin/hotplug-call gpsd
+                       ;;
+               "DEACTIVATE")
+                       env -i ACTION="$action" DEVICE="$device" \
+                               /sbin/hotplug-call gpsd
+                       ;;
+       esac
+}
+
+main "$@"
diff --git a/utils/gpsd/files/etc/hotplug.d/gpsd/00-debug b/utils/gpsd/files/etc/hotplug.d/gpsd/00-debug
new file mode 100644 (file)
index 0000000..ca55fcd
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+gps_log() {
+       local level="$1"; shift
+
+       [ "$level" = "debug" ] && return
+       logger -p "daemon.${level}" -t "gpsd(debug)[$$]" "hotplug: $*"
+}
+
+main() {
+       gps_log info "$(env)"
+}
+
+main "$@"
index ba5563e858558be8d16425c8c16620264bc26b77..ee1fabf69bed1ff183edb791e9d775a47c45aee3 100644 (file)
@@ -49,3 +49,12 @@ service_triggers() {
        procd_add_reload_trigger "$NAME"
        procd_add_validation validate_section_gpsd
 }
+
+service_started() {
+       local enabled
+
+       enabled="$(uci_get gpsd core enabled 0)"
+       [ "$enabled" = "0" ] && return
+
+       env -i ACTION="STARTED" /sbin/hotplug-call gpsd
+}